﻿#include <QApplication>
#include <QStandardItemModel>
#include <QFile>

#include <QTableView>
//#include <QMainWindow>

#include "frozencolumntablewidget.h"

int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(grades);

    QApplication app(argc,argv);

    QStandardItemModel *model = new QStandardItemModel();

    QFile file(":grades.txt");
    if (file.open(QFile::ReadOnly)) {
        QString line = file.readLine(200);
        QStringList list = line.simplified().split(",");
        model->setHorizontalHeaderLabels(list);

        int row = 0;
        QStandardItem *newItem = 0;//初始化指针。
        while (file.canReadLine()) { //当前行，是否可读？
            line = file.readLine(200);
            if (!line.startsWith("#") && line.contains(",")) {
                list = line.simplified().split(",");
                for (int col = 0; col < list.length(); ++col) {
                    newItem = new QStandardItem(list.at(col));
                    model->setItem(row,col,newItem);
                }//遍历列
                ++ row;
            }
        }//遍历行
        //当行数据遍历完毕时，数据已经全部添加到model中
    }

    file.close();


    //有了数据，现在就需要创建view来setmodel

    /*QMainWindow w;

    QTableView * table = new QTableView(&w);
    table->setModel(model);
    table->show();
    w.show();
    w.setCentralWidget(table);  //只有QMainWindow 才有这个方法
*/

    FrozenColumnTableWidget * tableWidget = new FrozenColumnTableWidget(model);

    tableWidget->resize(560,680);
    tableWidget->show();

    return app.exec();
}

